package com.stu.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.stu.commons.ServerResponse;
import com.stu.mapper.FlowMapper;
import com.stu.pojo.Flow;
import com.stu.pojo.Myorder;
import com.stu.service.IFlowService;
import com.stu.service.IMyorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class FlowServiceImpl implements IFlowService {
    @Autowired
    private FlowMapper flowMapper;
    @Autowired
    private IMyorderService  iMyorderService;
    @Override
    public ServerResponse save(Flow flow) {
        int rows = flowMapper.insert(flow);

        if(rows>0) {
            Myorder myorder = iMyorderService.selectById(flow.getMyorderId());
            myorder.setMyorderStatus(2);

            ServerResponse serverResponse = iMyorderService.updateMyorder(myorder);
            return ServerResponse.success("添加流水成功", true);
        }
        else
            return ServerResponse.fail("添加流水失败",false);
    }

    @Override
    public ServerResponse getFlow(String traceNo) {
        QueryWrapper<Flow> wrapper = new QueryWrapper<>();
        wrapper.eq("flow_id",traceNo);
        Flow flow = flowMapper.selectOne(wrapper);
        if(flow!=null)
            return ServerResponse.success("查询流水成功",flow);
        else
            return ServerResponse.fail("查询流水失败",null);
    }
}
